<template>
  <div class="Patient_master_index">
    <div class="pubBig Privilege">
      <div class="h0">
        <p class="lt"></p>
      </div>
      <div class="dDownMain">
        <div
          class="twoBox"
          :style="this.$route.query.Token ? 'top:50px;left:10px':'top: 100px'"
        >
          <!-- 上层查询卡片 -->
          <el-card
            class="box-card"
            style="height:150px"
          >
            <el-form
              label-position="right"
              label-width="120px"
              :model="formLabelAlign_search"
            >
              <el-form-item
                label="患者姓名："
                style="width:25%;display:inline-block"
              >
                <el-input
                  v-model="formLabelAlign_search.name"
                  style="width:50%"
                  size="mini"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="证件号码："
                style="width:25%;display:inline-block"
                size="mini"
              >
                <el-input
                  v-model="formLabelAlign_search.region"
                  style="width:50%"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="患者标识号："
                style="width:25%;display:inline-block"
                size="mini"
              >
                <el-input
                  v-model="formLabelAlign_search.type"
                  style="width:50%"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="开始时间："
                style="width:25%;display:inline-block"
                v-if="condition_show"
                size="mini"
              >
                <el-date-picker
                  v-model="formLabelAlign_search.time1"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                label="结束时间："
                style="width:25%;display:inline-block"
                v-if="condition_show"
                size="mini"
              >
                <el-date-picker
                  v-model="formLabelAlign_search.time2"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                label="文档类型："
                style="width:25%;display:inline-block"
                v-if="false"
                size="mini"
              >
                <template>
                  <el-select
                    filterable
                    v-model="formLabelAlign_search.value"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in options"
                      :key="item.flag"
                      :label="item.label"
                      :value="item.flag"
                    >
                    </el-option>
                  </el-select>
                </template>
              </el-form-item>
              <el-form-item style="width:25%;display:inline-block;">
                <el-button
                  size="mini"
                  type="primary"
                  @click="page.page=1,getTableData()"
                >查询</el-button>
                <el-button
                  size="mini"
                  @click="formLabelAlign_search = {}"
                >重置</el-button>
                <el-button
                  size="mini"
                  @click="more_condition(condition_show)"
                >{{condition_show ? '收起' : '更多...'}}</el-button>
              </el-form-item>
            </el-form>
          </el-card>
          <!-- 下层表格卡片 -->
          <el-card
            class="box-card"
            style="height:670px;margin-top:10px"
          >
            <div>
              <el-row>
                <el-col :span="12">
                  <span style="font-size:24px">主索引列表</span>
                  <el-button
                    v-if="false"
                    size="small"
                    style="margin-left:35px;margin-right:15px"
                  >生成所选</el-button>
                  <el-button
                    size="small"
                    style="margin-left:20px"
                    @click="addS"
                    :disabled="isOpens"
                  >批量生成</el-button>
                </el-col>
                <el-col :span="12">
                  <span>患者总数：<span style="color:red">990172</span>人</span>
                  <span style="margin-left:50px">文档总数：<span
                      style="color:red">990172</span>份</span>
                  <span style="margin-left:50px">隐私保护：</span>
                  <el-switch
                    v-model="switch_yinsi"
                    active-color="#13ce66"
                    inactive-color="#ff4949"
                    @change="Lokr"
                  >
                  </el-switch>
                  <el-button
                    type="text"
                    icon="el-icon-setting"
                    style="margin-left:15px;color:#000;font-size:18px"
                  ></el-button>
                </el-col>
              </el-row>
            </div>
            <!-- 表格 -->
            <div>
              <el-table
                ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange_patient"
                height="520"
              >
                <el-table-column
                  type="selection"
                  width="55"
                >
                </el-table-column>
                <el-table-column
                  label="主索引号"
                  prop="Code"
                >
                </el-table-column>
                <el-table-column
                  prop="Name"
                  label="患者姓名"
                >
                </el-table-column>
                <el-table-column
                  label="证件号码"
                  prop="IdCard"
                  width="165"
                >
                  <template slot-scope="scope">
                    <span
                      v-if="Lookrs">{{scope.row.IdCard | formatIDcard}}</span>
                    <span v-if="!Lookrs">{{scope.row.IdCard}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="联系电话"
                  prop="Telphone"
                  width="130"
                >
                  <template slot-scope="scope">
                    <span
                      v-if="Lookrs">{{scope.row.Telphone | formatPhone}}</span>
                    <span v-if="!Lookrs">{{scope.row.Telphone}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="性别名称"
                  prop="Gender"
                >
                </el-table-column>
                <el-table-column
                  label="出生日期"
                  prop=""
                >
                </el-table-column>
                <el-table-column
                  label="ABO血型"
                  prop="ABOCode"
                >
                </el-table-column>
                <el-table-column
                  label="RH血型"
                  prop="RHCode"
                >
                </el-table-column>
                <el-table-column label="联系人">
                </el-table-column>
                <el-table-column label="联系人电话">
                </el-table-column>
                <el-table-column label="联系人证件号">
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="180px"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-button
                      v-if="false"
                      size="mini"
                      icon="el-icon-search"
                      @click="openSearch(scope.row)"
                    ></el-button>
                    <el-button
                      size="mini"
                      icon="el-icon-plus"
                      @click="openAdd(scope.row)"
                    ></el-button>
                    <el-button
                      v-if="false"
                      size="mini"
                      icon="el-icon-refresh"
                      @click="openLook(scope.row)"
                    ></el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div
              class="block"
              style="text-align:center;padding-top:20px"
            >
              <el-pagination
                layout="prev, pager, next"
                :total="page.total"
                :page-size="page.limit"
                @current-change="page_change"
              >
              </el-pagination>
            </div>
          </el-card>
          <!-- 共享文档浏览弹层 -->
          <el-dialog
            :title="formLabelAlign_items_search.Name+' 共享文档生成'"
            :visible.sync="dialogVisible_search"
            width="50%"
            :before-close="handleClose_search"
            :append-to-body="true"
            :close-on-click-modal="false"
          >
            <el-form
              label-position="right"
              label-width="100px"
              :model="formLabelAlign_items_search"
            >
              <el-form-item
                label="文档名称："
                style="width:24%;display:inline-block"
              >
                <el-input v-model="formLabelAlign_items_search.name1">
                </el-input>
              </el-form-item>
              <el-form-item
                label="文档类型："
                style="width:24%;display:inline-block"
              >
                <template>
                  <el-select
                    v-model="formLabelAlign_items_search.value1"
                    filterable
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in options"
                      :key="item.flag"
                      :label="item.label"
                      :value="item.flag"
                    >
                    </el-option>
                  </el-select>
                </template>
              </el-form-item>
              <el-form-item
                label="版本号："
                style="width:24%;display:inline-block"
              >
                <template>
                  <el-select
                    v-model="formLabelAlign_items_search.type1"
                    filterable
                    placeholder="请选择"
                  >
                    <el-option
                      label="v1.0"
                      value="v1.0"
                    >
                    </el-option>
                    <el-option
                      label="v2.0"
                      value="v2.0"
                    >
                    </el-option>
                  </el-select>
                </template>
              </el-form-item>
              <el-form-item
                style="width:28%;display:inline-block;margin-left:-50px"
              >
                <el-button
                  size="mini"
                  type="primary"
                >查询</el-button>
                <el-button size="mini">重置</el-button>
              </el-form-item>
            </el-form>
            <div>
              <el-checkbox v-model="checked">全选</el-checkbox>
              <el-button
                size="small"
                style="margin-left:15px"
              >反选</el-button>
            </div>
            <span
              slot="footer"
              class="dialog-footer"
            >
              <el-button @click="handleClose_search">取 消</el-button>
              <el-button
                type="primary"
                @click="handleClose_search"
              >确 定</el-button>
            </span>
          </el-dialog>
          <!-- 共享文档生成弹层 -->
          <el-dialog
            :title="isTitle+' 共享文档生成'"
            :visible.sync="dialogVisible_Add"
            width="50%"
            :before-close="handleClose_Add"
            :append-to-body="true"
            :close-on-click-modal="false"
          >
            <el-form
              label-position="right"
              label-width="100px"
              :model="formLabelAlign_items_Add"
            >
              <el-form-item
                label="版本号："
                style="width:100%;display:inline-block"
              >
                <template>
                  <el-select
                    v-model="formLabelAlign_items_Add.type1"
                    filterable
                    placeholder="请选择"
                  >
                    <el-option
                      label="v1.0"
                      value="v1.0"
                    >
                    </el-option>
                    <el-option
                      label="v2.0"
                      value="v2.0"
                    >
                    </el-option>
                  </el-select>
                </template>
              </el-form-item>
              <el-form-item
                label="开始时间："
                style="width:50%;display:inline-block"
              >
                <el-date-picker
                  v-model="formLabelAlign_items_Add.value1"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                label="结束时间："
                style="width:50%;display:inline-block"
              >
                <el-date-picker
                  v-model="formLabelAlign_items_Add.value2"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-form>
            <div>
              <el-tabs value="emr" tab-position="left" type="border-card" style="height: 320px;" @tab-click="handleClick">
                <el-tab-pane label="EMR" name="emr">
                  <el-table
                    ref="multipleTable_EMPI"
                    :data="tableData_item_Add"
                    tooltip-effect="dark"
                    style="width: 100%;"
                    @selection-change="handleSelectionChange_EMPI"
                    height="300px"
              >
                <el-table-column
                  type="selection"
                  width="55"
                >
                </el-table-column>
                <el-table-column
                  label="文件类型"
                  prop="label"
                >
                </el-table-column>
                  </el-table>
                </el-tab-pane>
                <el-tab-pane label="EHR" name="ehr">
                  <el-table
                ref="multipleTable_EMPI_ehr"
                :data="tableData_item_Add_ehr"
                tooltip-effect="dark"
                style="width: 100%;"
                @selection-change="handleSelectionChange_EMPI_ehr"
                height="300px"
              >
                <el-table-column
                  type="selection"
                  width="55"
                >
                </el-table-column>
                <el-table-column
                  label="文件类型"
                  prop="label"
                >
                </el-table-column>
                  </el-table>
                </el-tab-pane>
              </el-tabs>          
            </div>
            <span
              slot="footer"
              class="dialog-footer"
            >
              <el-button @click="handleClose_Add">取 消</el-button>
              <el-button
                type="primary"
                @click="Add_P_E"
              >确 定</el-button>
            </span>
          </el-dialog>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data () {
    return {
      formLabelAlign_search: {
        name: '',
        region: '',
        type: '',
        time1: '',
        time2: ''
      },
      options: [
        {
          label: '病历概要', flag: 'EMR01',
        },
        {
          label: '门(急)诊病历', flag: 'EMR02',
        },
        {
          label: '急诊留观病历', flag: 'EMR03',
        },
        {
          label: '西药处方', flag: 'EMR04',
        },
        {
          label: '中药处方', flag: 'EMR05',
        },
        {
          label: '检查报告', flag: 'EMR06',
        },
        {
          label: '检验报告', flag: 'EMR07',
        },
        {
          label: '治疗记录', flag: 'EMR08',
        },
        {
          label: '一般手术记录', flag: 'EMR09',
        },
        {
          label: '麻醉术前访视记录', flag: 'EMR10',
        },
        {
          label: '麻醉记录', flag: 'EMR11',
        },
        {
          label: '麻醉术后访视记录', flag: 'EMR12',
        },
        {
          label: '输血记录', flag: 'EMR13',
        },
        {
          label: '待产记录', flag: 'EMR14',
        },
        {
          label: '阴道分娩记录', flag: 'EMR15',
        },
        {
          label: '剖宫产记录', flag: 'EMR16',
        },
        {
          label: '一般护理记录', flag: 'EMR17',
        },
        {
          label: '病重（病危）护理记录', flag: 'EMR18',
        },
        {
          label: '手术护理记录', flag: 'EMR19',
        },
        {
          label: '生命体征测量记录', flag: 'EMR20',
        },
        {
          label: '出入量记录', flag: 'EMR21',
        },
        {
          label: '高值耗材使用记录', flag: 'EMR22',
        },
        {
          label: '入院评估', flag: 'EMR23',
        },
        {
          label: '护理计划', flag: 'EMR24',
        },
        {
          label: '出院评估与指导', flag: 'EMR25',
        },
        {
          label: '手术知情同意书', flag: 'EMR26',
        },
        {
          label: '麻醉知情同意书', flag: 'EMR27',
        },
        {
          label: '输血治疗同意书', flag: 'EMR28',
        },
        {
          label: '特殊检查及特殊治疗同意书', flag: 'EMR29',
        },
        {
          label: '病危（重）通知书', flag: 'EMR30',
        },
        {
          label: '其他知情同意书', flag: 'EMR31',
        },
        {
          label: '住院病案首页', flag: 'EMR32',
        },
        {
          label: '中医住院病案首页', flag: 'EMR33',
        },
        {
          label: '入院记录', flag: 'EMR34',
        },
        {
          label: '24小时内入出院记录', flag: 'EMR35',
        },
        {
          label: '24小时内入院死亡记录', flag: 'EMR36',
        },
        {
          label: '住院病程记录 首次病程记录', flag: 'EMR37',
        },
        {
          label: '住院病程记录 日常病程记录', flag: 'EMR38',
        },
        {
          label: '住院病程记录-上级医师查房记录', flag: 'EMR39',
        },
        {
          label: '住院病程记录-疑难病例讨论记录', flag: 'EMR40',
        },
        {
          label: '住院病程记录-交接班记录', flag: 'EMR41',
        },
        {
          label: '住院病程记录-转科记录', flag: 'EMR42',
        },
        {
          label: '住院病程记录-阶段小结', flag: 'EMR43',
        },
        {
          label: '住院病程记录-抢救记录', flag: 'EMR44',
        },
        {
          label: '住院病程记录-会诊记录', flag: 'EMR45',
        },
        {
          label: '住院病程记录-术前小结', flag: 'EMR46',
        },
        {
          label: '住院病程记录-术前讨论', flag: 'EMR47',
        },
        {
          label: '住院病程记录-术后首次病程记录', flag: 'EMR48',
        },
        {
          label: '住院病程记录-出院记录', flag: 'EMR49',
        },
        {
          label: '住院病程记录-死亡记录', flag: 'EMR50',
        },
        {
          label: '住院病程记录-死亡病例讨论记录', flag: 'EMR51',
        },
        {
          label: '住院医嘱', flag: 'EMR52',
        },
        {
          label: '出院小结', flag: 'EMR53',
        }
      ],
      switch_yinsi: true,
      tableData: [{
        name: '张三',
        idCard: '3717**********7314',
        temphone: '15538107729',
        six: '男'
      }, {
        name: '李四',
        idCard: '3717**********7729',
        temphone: '13568762962',
        six: '男'
      }, {
        name: '王五',
        idCard: '4102**********552X',
        temphone: '18066635712',
        six: '女'
      }],
      multipleSelection: [],
      dialogVisible_Add: false,
      dialogVisible_search: false,
      formLabelAlign_items_search: {},
      formLabelAlign_items_Add: {},
      checked: true,
      tableData_item_Add: [
        {
          label: '病历概要', flag: 'EMR01',
        },
        {
          label: '门(急)诊病历', flag: 'EMR02',
        },
        {
          label: '急诊留观病历', flag: 'EMR03',
        },
        {
          label: '西药处方', flag: 'EMR04',
        },
        {
          label: '中药处方', flag: 'EMR05',
        },
        {
          label: '检查报告', flag: 'EMR06',
        },
        {
          label: '检验报告', flag: 'EMR07',
        },
        {
          label: '治疗记录', flag: 'EMR08',
        },
        {
          label: '一般手术记录', flag: 'EMR09',
        },
        {
          label: '麻醉术前访视记录', flag: 'EMR10',
        },
        {
          label: '麻醉记录', flag: 'EMR11',
        },
        {
          label: '麻醉术后访视记录', flag: 'EMR12',
        },
        {
          label: '输血记录', flag: 'EMR13',
        },
        {
          label: '待产记录', flag: 'EMR14',
        },
        {
          label: '阴道分娩记录', flag: 'EMR15',
        },
        {
          label: '剖宫产记录', flag: 'EMR16',
        },
        {
          label: '一般护理记录', flag: 'EMR17',
        },
        {
          label: '病重（病危）护理记录', flag: 'EMR18',
        },
        {
          label: '手术护理记录', flag: 'EMR19',
        },
        {
          label: '生命体征测量记录', flag: 'EMR20',
        },
        {
          label: '出入量记录', flag: 'EMR21',
        },
        {
          label: '高值耗材使用记录', flag: 'EMR22',
        },
        {
          label: '入院评估', flag: 'EMR23',
        },
        {
          label: '护理计划', flag: 'EMR24',
        },
        {
          label: '出院评估与指导', flag: 'EMR25',
        },
        {
          label: '手术知情同意书', flag: 'EMR26',
        },
        {
          label: '麻醉知情同意书', flag: 'EMR27',
        },
        {
          label: '输血治疗同意书', flag: 'EMR28',
        },
        {
          label: '特殊检查及特殊治疗同意书', flag: 'EMR29',
        },
        {
          label: '病危（重）通知书', flag: 'EMR30',
        },
        {
          label: '其他知情同意书', flag: 'EMR31',
        },
        {
          label: '住院病案首页', flag: 'EMR32',
        },
        {
          label: '中医住院病案首页', flag: 'EMR33',
        },
        {
          label: '入院记录', flag: 'EMR34',
        },
        {
          label: '24小时内入出院记录', flag: 'EMR35',
        },
        {
          label: '24小时内入院死亡记录', flag: 'EMR36',
        },
        {
          label: '住院病程记录 首次病程记录', flag: 'EMR37',
        },
        {
          label: '住院病程记录 日常病程记录', flag: 'EMR38',
        },
        {
          label: '住院病程记录-上级医师查房记录', flag: 'EMR39',
        },
        {
          label: '住院病程记录-疑难病例讨论记录', flag: 'EMR40',
        },
        {
          label: '住院病程记录-交接班记录', flag: 'EMR41',
        },
        {
          label: '住院病程记录-转科记录', flag: 'EMR42',
        },
        {
          label: '住院病程记录-阶段小结', flag: 'EMR43',
        },
        {
          label: '住院病程记录-抢救记录', flag: 'EMR44',
        },
        {
          label: '住院病程记录-会诊记录', flag: 'EMR45',
        },
        {
          label: '住院病程记录-术前小结', flag: 'EMR46',
        },
        {
          label: '住院病程记录-术前讨论', flag: 'EMR47',
        },
        {
          label: '住院病程记录-术后首次病程记录', flag: 'EMR48',
        },
        {
          label: '住院病程记录-出院记录', flag: 'EMR49',
        },
        {
          label: '住院病程记录-死亡记录', flag: 'EMR50',
        },
        {
          label: '住院病程记录-死亡病例讨论记录', flag: 'EMR51',
        },
        {
          label: '住院医嘱', flag: 'EMR52',
        },
        {
          label: '出院小结', flag: 'EMR53',
        }
      ], 
      tableData_item_Add_ehr: [
        {
          label: '个人基本信息', flag: 'EHR01',
        },
        {
          label: '出生医学证明', flag: 'EHR02',
        },
        {
          label: '新生儿家庭访视', flag: 'EHR03',
        },
        {
          label: '儿童健康检查', flag: 'EHR04',
        },
        {
          label: '首次产前随访服务', flag: 'EHR05',
        },
        {
          label: '产前随访', flag: 'EHR06',
        },
        {
          label: '产后访视', flag: 'EHR07',
        },
        {
          label: '产后42天健康体检', flag: 'EHR08',
        },
        {
          label: '预防接种报告', flag: 'EHR09',
        },
        {
          label: '传染病报告', flag: 'EHR10',
        },
        {
          label: '死亡医学证明', flag: 'EHR11',
        },
        {
          label: '高血压患者随访服务', flag: 'EHR12',
        },
        {
          label: '2型糖尿病患者随访服务', flag: 'EHR13',
        },
        {
          label: '重性精神疾病患者个人信息登记', flag: 'EHR14',
        },
        {
          label: '重性精神疾病患者随访服务', flag: 'EHR15',
        },
        {
          label: '成人健康体检（家族史和预防接种史缺失）', flag: 'EHR16',
        },
        {
          label: '门诊摘要', flag: 'EHR17',
        },
        {
          label: '住院摘要', flag: 'EHR18',
        },
        {
          label: '会诊记录', flag: 'EHR19',
        },
        {
          label: '转诊（院）记录', flag: 'EHR20',
        }
      ],
      condition_show: false,
      page: {
        page: 1,
        limit: 10,
        total: 1
      },
      isTitle: '',
      isPatientCode: [],//患者主索引列表
      theAddType: 2,//确定按钮的类型 1 批量 2 单个
      isEMPI_list: [], // 文件类型列表
      isEMPI_list_ehr: [], // 文件类型列表ehr
      PatientCode: '',//单个患者索引号
      Lookrs: true,//隐私保护开关
      isPatientName: [],// 患者名字列表,
      isOpens: true, // 控制批量生成按钮状态
    };
  },
  methods: {
    toggleSelection (rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange_patient (val) {//患者选中事件
      let arr = []
      let arr_name = []
      for (var i in val) {
        arr.push(val[i].Code)
        arr_name.push(val[i].ContactName)
      }
      this.isPatientCode = arr
      this.isPatientName = arr_name
      if (arr.length <= 0) {
        this.theAddType = 2
        this.isOpens = true
      }
      if (arr.length > 0) {
        this.theAddType = 1
        this.isOpens = false
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    handleClose_search () {
      this.dialogVisible_search = false
      this.formLabelAlign_items_search = {}
    },
    openSearch (val) {
      console.log(val);
      this.formLabelAlign_items_search = val
      this.dialogVisible_search = true
    },
    handleClose_Add () { // 弹层关闭
      this.dialogVisible_Add = false
      this.formLabelAlign_items_Add = {}
      this.isEMPI_list = []
      this.$refs.multipleTable_EMPI.clearSelection();
      this.$refs.multipleTable_EMPI_ehr.clearSelection();
    },
    Add_P_E () { // 弹层确定
      if (this.isEMPI_list.length!=0){ 
        //EMR生成
        if (this.theAddType == 1) {
          // 批量
          let body = {
            version: this.formLabelAlign_items_Add.type1,
            startTime: this.formLabelAlign_items_Add.value1,
            endTime: this.formLabelAlign_items_Add.value2,
            codeData: this.isPatientCode,
            fileData: this.isEMPI_list
          }
          this.$post("/DocumentManage/Main/BatchCDA", body).then(res => {
            if (res.code == 0) {
              this.handleClose_Add()
              this.$refs.multipleTable.clearSelection();
              this.$message({
                message: '操作成功',
                type: 'success'
              });
            }
          })
        }
        else if (this.theAddType == 2) {
          // 单个
          let body = {
            version: this.formLabelAlign_items_Add.type1,
            startTime: this.formLabelAlign_items_Add.value1,
            endTime: this.formLabelAlign_items_Add.value2,
            codeData: this.PatientCode,
            fileData: this.isEMPI_list
          }
          this.$post("/DocumentManage/Main/CreateCDA", body).then(res => {
            if (res.code == 0) {
              this.handleClose_Add()
              this.$message({
                message: '操作成功',
                type: 'success'
              });
            }
          })
        }
      }
      if (this.isEMPI_list_ehr.length!=0){ 
        //EHR生成
        if (this.theAddType == 1) {
          // 批量
          let body = {
            version: this.formLabelAlign_items_Add.type1,
            startTime: this.formLabelAlign_items_Add.value1,
            endTime: this.formLabelAlign_items_Add.value2,
            codeData: this.isPatientCode,
            fileData: this.isEMPI_list_ehr
          }
          this.$post("/DocumentManage/Main/BatchEHRCDA", body).then(res => {
            if (res.code == 0) {
              this.handleClose_Add()
              this.$refs.multipleTable.clearSelection();
              this.$message({
                message: '操作成功',
                type: 'success'
              });
            }
          })
        }
        else if (this.theAddType == 2) {
          // 单个
          let body = {
            version: this.formLabelAlign_items_Add.type1,
            startTime: this.formLabelAlign_items_Add.value1,
            endTime: this.formLabelAlign_items_Add.value2,
            codeData: this.PatientCode,
            fileData: this.isEMPI_list_ehr
          }
          this.$post("/DocumentManage/Main/CreateEHRCDA", body).then(res => {
            if (res.code == 0) {
              this.handleClose_Add()
              this.$message({
                message: '操作成功',
                type: 'success'
              });
            }
          })
        }
      }
    },
    openAdd (val) { // 单个下载
      console.log(val);
      this.PatientCode = val.Code
      this.isTitle = val.Name
      this.theAddType = 2
      this.dialogVisible_Add = true
    },
    handleSelectionChange_EMPI (val) { // 弹层EMPI选择
      let arr = []
      for (var i in val) {
        arr.push(val[i].flag)
      }
      console.log(arr);
      this.isEMPI_list = arr
    },
    handleSelectionChange_EMPI_ehr (val) { // 弹层EMPI选择
      let arr = []
      for (var i in val) {
        arr.push(val[i].flag)
      }
      console.log(arr);
      this.isEMPI_list_ehr = arr
    },
    openLook (val) {
      console.log(val);
      this.$message({
        message: '患者信息不完整无法调阅',
        type: 'warning'
      });
    },
    more_condition (val) {
      // console.log(val);
      if (val) {
        this.condition_show = false
        this.formLabelAlign_search.time1 = ''
        this.formLabelAlign_search.time2 = ''
        this.formLabelAlign_search.value = ''
      }
      if (!val) {
        this.condition_show = true
      }
    },
    getTableData () {// 获取表格数据
      this.$post("/DocumentManage/Main/PatientList?name=" + this.formLabelAlign_search.name + "&idCard=" + this.formLabelAlign_search.region + "&code=" + this.formLabelAlign_search.type + "&startTime=" + this.formLabelAlign_search.time1 + "&endTime=" + this.formLabelAlign_search.time2 + "&page=" + this.page.page + "&limit=" + this.page.limit).then(res => {
        if (res.code == 0) {
          console.log(res);
          this.page.total = res.data.TotalCount
          this.tableData = res.data.list
        }
      })
    },
    page_change (val) {
      this.page.page = val
      this.getTableData()
    },
    addS () {// 批量生成
      this.dialogVisible_Add = true
      this.isTitle = this.isPatientName
    },
    Lokr (val) { // 隐私保护切换事件
      this.Lookrs = val
    },
    handleClick(tab, event) {
     
    }
  },
  mounted () {
    // document.getElementById("2").focus();
    this.getTableData()
  },
  created () {
    if (this.$route.query.Token) {
      localStorage.setItem('Token', this.$route.query.Token)
    }
  },
  filters: {
    formatIDcard (value) { // 身份证
      if (!value) return '';
      let str = value;
      str = str.toString().replace(/^(.{3})(?:\w+)(.{4})$/, '$1***********$2')
      return str;
    },
    formatPhone (value) { // 电话
      if (!value) return '';
      let str = value;
      str = str.toString().replace(/^(\d{3})(\d{4})(\d{4})/g, '$1****$3')
      return str;
    }
  }
};
</script>
<style lang="scss">
.Patient_master_index {
  .top-input {
    display: inline-block;
    width: 350px;
  }

  .box-top {
    margin-top: 15px;
    margin-left: 5px;
  }
}
</style>
